<template>
  <view class="content">
      <view v-for="item in otherQuestions" :key="item.label" class="question">
          <view class="question-label">{{item.label}}</view>
          <view class="question-value">{{item.value | question}}</view>
      </view>
      <button class="modify-btn" @click="gotoModifyPage">修改</button>
  </view>
</template>

<script>
import {getData } from "../../api/index"

export default {
  data() {
    return {
      name: '',
      identityType:'',
      nation:'',
      age:'',
      phone:'',
      isolationPoint:'',
      sex :'0',
      rzfh:'--',

      id:'',
      formData: {
         otherDiseases:'',
      },   
      otherQuestions:[
        {
          label: "做事时没有兴趣或乐趣",
          value: "完全没有",
        },
        {
          label: "感到心情低落、沮丧或绝望",
          value: "完全没有",
        },
        {
          label: "入睡困难、易醒或睡眠过多",
          value: "完全没有",
        },
        {
          label: "感到疲倦或没有精力",
          value: "完全没有",
        },
        {
          label: "食欲不振或吃得过多",
          value: "完全没有",
        },
        {
          label: "觉得自己很糟糕或自己很失败，或让自己或家人失望",
          value: "完全没有",
        },
        {
          label: "做事情难以专注，例如读报纸或看电视",
          value: "完全没有",
        },
        {
          label: "行动或说话速度缓慢到别人已经觉察到，或刚好相反一变得比平日更烦躁或坐立不安，以至于走来走去比平常多很多",
          value: "完全没有",
        },
        {
          label: "有不如死掉的想法或以某种方式伤害自己的念头",
          value: "完全没有",
        },
      ],
      text: "",
      userName:'',
      userCardId:'',
    };
  },
  filters: {
    question:(value)=>{
      if(value==0){
        return '无'
      }else if(value==1){
        return '轻度'
      }else if(value==2){
        return '中度'
      }else if(value==3){
        return '重度'
      }else if(value==4){
        return '极重度'
      }else{
        return '未评估'
      }
    }
  },
  components: {
    /*  uniFroms ,
			 uniFormsItem,  */
  },
  onLoad(e) {
    this.addPerson = e.addPerson
    let {cardId,name} = uni.getStorageSync("personInfo");
    this.userCardId = cardId;
    this.userName = name;
    if(this.addPerson){
      this.getLatest()
    }else{
      this.getList();
    }
  },
  methods: {
    gotoModifyPage(){
      uni.navigateTo({
        url: './qnarModify?type=dataPhq9'
      })
    },
    getList(){
      let  {personId} = uni.getStorageSync("personInfo")
      let parms = {personId}
      getData('comprehensive','get',parms).then( (res)=>{
         var dataPhq9 = JSON.parse(res[0].dataPhq9);
         if(dataPhq9 !=null && dataPhq9 !=''){
           dataPhq9.forEach((item,index) => {
              console.log(item)
              this.otherQuestions[index].value = item.value
           });
         }
      } ).catch((e)=>{
        console.log( e);
      })
    },
    getLatest(){
      let param = {
        name:this.userName,
        identity:this.userCardId
      }
      getData('latest','get',param).then(res=>{
        if(!res.dataPhq9)return
        var dataPhq9 = JSON.parse(res.dataPhq9);
         if(dataPhq9 !=null && dataPhq9 !=''){
           dataPhq9.forEach((item,index) => {
              console.log(item)
              this.otherQuestions[index].value = item.value
           });
         }
      })
    }
  },
};
</script>

<style lang='scss' scrope>
   
  .content {
    display: flex;
    flex-direction: column;
    padding: 0 32rpx 32rpx;
    padding-bottom: 180rpx;
  }
  .question{
    &-label{
      font-size: 30rpx;
      color:#666;
      padding:40rpx 0 20rpx;
    }
    &-value{
      color:#999;
      font-size: 34rpx;
      padding-top: 10rpx;
      padding-bottom:10rpx;
      border-bottom:1px solid #d0d0d0;
    }
  }
  .modify-btn {
    width: 328rpx;
    color: #000;
    font-size: 34rpx;
    background: #fff;
    border: 1rpx solid #ccc;
    border-radius: 16rpx;
    margin-right: 30rpx;
    position: fixed;
    bottom: 58rpx;
    left: 50%;
    transform: translateX(-50%);
  }
</style>

